function flashHandler(sid, anchorid, prefix) {
	var isdebug   = true;
	var anoymous  = 2147483648;
	var cmd       =  {REQ_SEND_MSG:600012, MMFunc_SendMsg:104, REQ_GET_STUDIO_MEMBERS:600109, MMFunc_GetStudioMembers:533, REQ_GAG_USER:600121, MMFunc_GagUser:535, REQ_KICK_USER:600122,  MMFunc_KickOutUser:536};
	var viewer    = {};
	var that      = this;
	this.sid      = sid;
	this.anchorid = anchorid;
	this.userid   = 0;
	this.flash    = prefix + sid;
	this.im       = null;
	this.members  = new Array();
	this.log      = function() {
		for (var i = arguments.length - 1; i >= 0; i--) {
			if (console && console.debug) {
				console.debug(arguments[i]);
			};
		};
	};
	//执行命令
	this.sendCmd = function(cmd, cliid, data) {
		if(!this.im) {
			this.im = document.getElementById(this.flash);
		}
		this.im && this.im.js_flash("sendIM", cmd, cliid, data);
	}
	//发送聊天信息
	this.sendChat = function(msg, i2uin) {
		if (msg.length < 1) {
			return;
		};
        var stime = Math.round(new Date().getTime()/1000);
        var msgid = "IGG_TEXT#"+this.sid+"#"+this.userid+"#"+i2uin+"#"+stime;
        i2uin     = parseInt(i2uin);
		var reqs  = {MsgType:1, StudioId:this.sid, ToUin:i2uin, ClientMsgId:msgid, MsgContent:msg, EmojiFlag:0, CreateTime:parseInt(stime)};
		var data  = {Count:1, List:[reqs]};
		this.sendCmd(cmd.REQ_SEND_MSG, cmd.MMFunc_SendMsg, data);
		this.receive(this.userid, msg);
	};
    //禁言/解禁用户
	this.gagUser = function(touin, gagFlag) {
		var data = {OpType:parseInt(gagFlag), StudioId:this.sid, GagUin:parseInt(touin)};
		this.sendCmd(cmd.REQ_GAG_USER, cmd.MMFunc_GagUser, data);
	};
	//踢掉用户
	this.kickUser = function(touin) {
		var data = {StudioId:this.sid, OutUin:parseInt(touin)};
		this.sendCmd(cmd.REQ_KICK_USER, cmd.MMFunc_KickOutUser, data);
	};
	//获取在线用户
	this.roomMembers = function(){
		var data = {StudioId:this.sid};
		this.sendCmd(cmd.REQ_GET_STUDIO_MEMBERS, cmd.MMFunc_GetStudioMembers, data);
	};
	
	this.getUser = function(uin) {
		if(Ext.isArray(uin)) {
			uin = uin.join(',');
		}
		var self = this;
		Ext.Ajax.request({
			url: "/live/as3/get/s-"+uin+"/sid-"+self.sid+".html",
			success: function(rsp, req){
				var data = Ext.decode(rsp.responseText);
				for(var userid in data.users) {
					viewer[userid] = data.users[userid];
				}
			},
		});
	};

	//获取指定的用户信息
	this.getViewer = function(uin) {
		var self = this;
		uin      = parseInt(uin);
		if(!viewer[uin]) {
			this.getUser(uin);
		}
		return (!!viewer[uin])? viewer[uin]:null;
	};
	
	this.receive  = function(uin, msg) {
		var self = this;
		var el   = Ext.get("Chats"+this.sid);
		if(uin > anoymous) {
			el.createChild({tag:'li', html: '[anonymous user]'+msg});
		} else {
			var user = this.getViewer(uin);
			if(user) {
				el.createChild({tag:'li', html: '['+((user)? user.nick:'anonymous user')+']'+msg});
			} else {
				setTimeout(function(){
					var user = self.getViewer(uin);
					el.createChild({tag:'li', html: '['+((user)? user.nick:'anonymous user')+']'+msg});
				}, 1000);
			}
		}
	};

	//获取flah的消息回调
	this.flash2js = function(msgtype, imcmd, msg) {
		if (!arguments || arguments.length < 2) {
			isdebug && that.log("im callback null msg");
			return;
		}
		isdebug && that.log(arguments);
		if (msgtype == "connect") {
			if (imcmd == 0) {
				that.log("im connect error!");
				return;
			};
			this.userid = parseInt(msg);
			this.getUser(that.userid);
			return;
		};
		if (msgtype != "immsg" || !msg || (msg.BaseResponse && msg.BaseResponse.Ret != 0)) {
			that.log(msg);
			return;
		};
		switch(imcmd) {
			case 10600105://进入房间
				that.roomMembers(that.sid);
				break;
			case 10600109://获取用户回调
				if (msg.Count > 0) {
					for (var i = 0; i < msg.Count; i++) {
						uin = msg.MemberList[i].Uin;
						(uin < anoymous) && that.members.push(uin);
					}
					isdebug && that.log(that.members);
				}
				break;
			case 600502:
				switch(msg.MsgType) {
				case 1://消息接收
					that.receive(msg.FromUin, msg.MsgContent.Buff);
					break;
				case 20002://观众进来
					(msg.FromUin < anoymous) && that.members.push(msg.FromUin);
					break;
				case 20003://观众离开
					(msg.FromUin < anoymous) && that.members.remove(msg.FromUin);
					break;
				case 20006://踢掉
					break;
				case 20005://禁言
					break;
				case 20008://账号在另外一个地方登录 
					Ext.msg.alert("account had login other browser.")
					break;
				default:
					isdebug && that.log(imcmd, msg);
				}
				break;
			default:
				isdebug && that.log(imcmd, msg);
		}
	};
}
